package cc.jorange.service.init;

import cc.jorange.bean.Poster;
import cc.jorange.bean.Work;
import cc.jorange.common.Clock;
import cc.jorange.dao.PosterDao;
import cc.jorange.dao.WorkDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;

/**
 * 添加数据
 */
@Component
public class InitDto3 {

    private Clock clock = Clock.DEFAULT;

    @Autowired
    private WorkDao workDao;
    @Autowired
    private PosterDao posterDao;

    @PostConstruct
    public void init() {
        this.works();
        this.poster();
    }

    private void poster() {
        this.createPoster(29, "", "d", "image/poster/wmdsg.png", 83L, 0);
        this.createPoster(30, "", "d", "image/poster/msm.png", 84L, 1);
    }

    private void works() {
        this.createWork(83L, "《我们的时光》", "TFBOYS", "", "", "", "", "<embed src=\"https://imgcache.qq.com/tencentvideo_v1/playerv3/TPout.swf?max_age=86400&v=20161117&vid=h0025mylc42&auto=0\" allowFullScreen=\"true\" quality=\"high\" width=\"100%\" height=\"563px\" align=\"middle\" allowScriptAccess=\"always\" type=\"application/x-shockwave-flash\"></embed>", "2018/wmdsg.png", "type", "2018", "HOT,NEW");
        this.createWork(84L, "《目属目》", "BBT", "", "", "", "", "<embed src=\"https://imgcache.qq.com/tencentvideo_v1/playerv3/TPout.swf?max_age=86400&v=20161117&vid=x0025ljhwmy&auto=0\" allowFullScreen=\"true\" quality=\"high\" width=\"100%\" height=\"563px\" align=\"middle\" allowScriptAccess=\"always\" type=\"application/x-shockwave-flash\"></embed>", "2018/msm.png", "type", "2018", "NEW");
    }

    private void createPoster(long id, String title, String description, String img, Long workId, int score) {
        Poster p = new Poster();
        p.setId(id);
        p.setTitle(title);
        p.setImg(img);
        p.setWorkId(workId);
        p.setDescription(description);
        p.setScore(score);
        p.setTs(clock.getCurrentDate());
        posterDao.save(p);
    }

    private void createWork(long id, String title, String author, String company, String description, String blog, String team, String url, String img, String type, String createDate, String tags) {
        Work work = new Work();
        work.setId(id);
        work.setTitle(title);
        work.setAuthor(author);
        work.setCompany(company);
        work.setDescription(description);
        work.setBlog(blog);
        work.setTeam(team);
        work.setUrl(url);
        work.setImg(img);
        work.setType(type);
        work.setCreateDate(createDate);
        work.setTags(tags);
        work.setTs(clock.getCurrentDate());
        workDao.save(work);
    }

}
